package com.wxmit.module.system.domain.vo;

import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.wxmit.base.enums.YesOrNoEnum;
import com.wxmit.framework.excel.annotation.ExcelCellSelect;
import com.wxmit.module.system.domain.SysRole;
import com.wxmit.module.system.domain.converters.SexWriteConverterContext;
import com.wxmit.module.system.service.impl.SysUserServiceImpl;
import com.wxmit.starter.xfile.core.annotation.FileRealm;
import com.wxmit.system.base.core.BaseEntity;
import lombok.Data;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.List;

/**
 * @author xiongchuyun
 * @date 2023/6/20
 *
 */
@Data
public class SysUserVO extends BaseEntity {

    private static final long serialVersionUID = 1L;

    @TableId(type = IdType.AUTO)
    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;

    @NotNull(message = "部门不能为空")
    private Long deptId;

    @NotNull(message = "用户名不能为空")
    @ExcelProperty("登录名")
    private String userName;

    @NotNull(message = "用户昵称不能为空")
    @ExcelProperty("昵称")
    private String nickName;

    @ExcelProperty("邮件")
    @Email(message="用户邮件格式有误")
    private String email;

    @ExcelProperty("手机号")
    private String phone;

    @ExcelProperty(value="性别",converter = SexWriteConverterContext.class)
    @ExcelCellSelect(enumClass= YesOrNoEnum.class,enumField = "genderLabel")
    private String sex;

    @FileRealm
    private String avatar;

    /** 密码 */
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    private String password;

    private String status;

    private String loginIp;

    /**
     *  是否默认密码
     */
    private String dfPw;

    /**
     *  是否封禁
     */
    private String ban;

    /**
     *  当日的登录错误次数
     */
    private int loginErrOfDay;

    /** 登录时间 */
    @JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8")
    private Date loginDate;

    /** 上次登录时间 */
    @JsonFormat(pattern = "yyyy-MM-dd",timezone="GMT+8")
    private Date preLoginDate;

    /** 上次登录地点 */
    private String preLoginLocation;


    @TableField(exist = false)
    private List<SysRole> roles;

    @TableField(exist = false)
    private List<Long> roleIds;

    @TableField(exist = false)
    @ExcelProperty("部门名")
    @ExcelCellSelect(handler = SysUserServiceImpl.class)
    private String deptName;

    @TableField(exist = false)
    private List<String> permissionList;
}
